﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace ArduinoSketch.Core
{
    [Serializable]
    [XmlRoot("Solution")]
    public class SolutionEntity
    {
        private string _solutionName;
        private string _solutionPath;
        private List<ProjectEntity> _projects; 

        [XmlArrayItem("Projects", typeof(ProjectEntity))]
        [XmlArray("Project")]
        public List<ProjectEntity> Projects
        {
            get { return _projects; }
            set { _projects = value; }
        }

        [XmlElement("SolutionName")]
        public string SolutionName
        {
            get { return _solutionName; }
            set { _solutionName = value; }
        }

        [XmlElement("SolutionPath")]
        public string SolutionPath
        {
            get { return _solutionPath; }
            set { _solutionPath = value; }
        }

        public SolutionEntity()
        {
            Projects = new List<ProjectEntity>();
        }
    }

    [Serializable]
    [XmlRoot("Projects")]
    public class ProjectEntity
    {
        private string _projectName;

        [XmlElement("ProjectName")]
        [DisplayName("Project Name")]
        [Description("Project Folder/Project Name")]
        [ReadOnly(true)]
        [Category("Properties")]
        public string ProjectName
        {
            get { return _projectName; }
            set { _projectName = value; }
        }
        private string _projectPath;

        [XmlElement("ProjectPath")]
        [DisplayName("Project Path")]
        [Description("Project Folder/Project Path")]
        [ReadOnly(true)]
        [Category("Properties")]
        public string ProjectPath
        {
            get { return _projectPath; }
            set { _projectPath = value; }
        }

        private List<ProjectFileEntity> _projectFiles;

        [XmlArrayItem("ProjectFiles", typeof(ProjectFileEntity))]
        [XmlArray("ProjectFile")]
        [Browsable(false)]
        public List<ProjectFileEntity> ProjectFiles
        {
            get { return _projectFiles; }
            set { _projectFiles = value; }
        }

        private string _hardwareProfile;

        [XmlElement("HardwareProfile")]
        [Browsable(false)]
        public string HardwareProfile
        {
            get { return _hardwareProfile; }
            set 
            { 
                _hardwareProfile = value; 
            }
        }

        public ProjectEntity()
        {
            this.ProjectFiles = new List<ProjectFileEntity>();
        }
    }

    [Serializable]
    [XmlRoot("ProjectFiles")]
    public class ProjectFileEntity
    {
        private string _fileName;

        [XmlElement("FileName")]
        [DisplayName("Name")]
        [Description("Project Folder/File Name")]
        [ReadOnly(true)]
        [Category("Properties")]
        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }
        private string _filePath;

        [XmlElement("FilePath")]
        [DisplayName("File Path")]
        [Description("Project Folder/File Path")]
        [ReadOnly(true)]
        [Category("Properties")]
        public string FilePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        private ProjectEntity _project;

        [Browsable(false)]
        [XmlIgnore()]
        public ProjectEntity Project
        {
            get { return _project; }
            set { _project = value; }
        }

        public ProjectFileEntity()
        {

        }
    }

    [Serializable]
    [XmlRoot("Hardwares")]
    public class Hardwares
    {
        private List<HardwareProfile> _profile;

        [XmlArrayItem("HardwareProfiles", typeof(HardwareProfile))]
        [XmlArray("Profile")]
        public List<HardwareProfile> Profile
        {
            get { return _profile; }
            set { _profile = value; }
        }

        public Hardwares() 
        {
            Profile = new List<HardwareProfile>();
        }
    }

    [Serializable]
    [XmlRoot("Programers")]
    public class Programers
    {
        private List<Programer> _programers;

        [XmlArrayItem("Programers", typeof(Programer))]
        [XmlArray("Programer")]
        public List<Programer> ProgramersList
        {
            get { return _programers; }
            set { _programers = value; }
        }

        public Programers() { }
    }

    [Serializable]
    [XmlRoot("Programer")]
    public class Programer
    {
        private string _name;

        [XmlElement()]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _communication;

        [XmlElement()]
        public string Communication
        {
            get { return _communication; }
            set { _communication = value; }
        }

        private string _protocol;

        [XmlElement()]
        public string Protocol
        {
            get { return _protocol; }
            set { _protocol = value; }
        }

        private bool _force;

        [XmlElement()]
        public bool Force
        {
            get { return _force; }
            set { _force = value; }
        }

        public Programer() { }
    }

    [Serializable]
    [XmlRoot("Hardware")]
    public class HardwareProfile
    {
        private string _name;

        [XmlElement()]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private string _uploadPotocal;

        [XmlElement()]
        public string UploadPotocal
        {
            get { return _uploadPotocal; }
            set { _uploadPotocal = value; }
        }
        private string _uploadMaximum;

        [XmlElement()]
        public string UploadMaximum
        {
            get { return _uploadMaximum; }
            set { _uploadMaximum = value; }
        }
        private string _uploadSpeed;

        [XmlElement()]
        public string UploadSpeed
        {
            get { return _uploadSpeed; }
            set { _uploadSpeed = value; }
        }
        private string _mcu;

        [XmlElement()]
        public string Mcu
        {
            get { return _mcu; }
            set { _mcu = value; }
        }
        private string _fcpu;

        [XmlElement()]
        public string Fcpu
        {
            get { return _fcpu; }
            set { _fcpu = value; }
        }
        private string _core;

        [XmlElement()]
        public string Core
        {
            get { return _core; }
            set { _core = value; }
        }

        private string _bootloaderLowFuses;

        [XmlElement()]
        public string BootloaderLowFuses
        {
            get { return _bootloaderLowFuses; }
            set { _bootloaderLowFuses = value; }
        }

        private string _bootloaderHighFuses;

        [XmlElement()]
        public string BootloaderHighFuses
        {
            get { return _bootloaderHighFuses; }
            set { _bootloaderHighFuses = value; }
        }

        private string _bootloaderExtenedFuses;

        [XmlElement()]
        public string BootloaderExtenedFuses
        {
            get { return _bootloaderExtenedFuses; }
            set { _bootloaderExtenedFuses = value; }
        }

        private string _bootloaderFile;

        [XmlElement()]
        public string BootloaderFile
        {
            get { return _bootloaderFile; }
            set { _bootloaderFile = value; }
        }

        private string _bootLoaderPath;

        [XmlElement()]
        public string BootLoaderPath
        {
            get { return _bootLoaderPath; }
            set { _bootLoaderPath = value; }
        }

        private string _bootloaderLockBit;

        [XmlElement()]
        public string BootloaderLockBit
        {
            get { return _bootloaderLockBit; }
            set { _bootloaderLockBit = value; }
        }

        private string _bootloaderUnlockBit;

        [XmlElement()]
        public string BootloaderUnlockBit
        {
            get { return _bootloaderUnlockBit; }
            set { _bootloaderUnlockBit = value; }
        }

        public HardwareProfile()
        {

        }

        public override string ToString()
        {
            return this.Name;
        }
    }
}
